import Interceptor from './core/interceptor';
import Request from './index';

export const globalInterceptor = {
  request: new Interceptor(),
  response: new Interceptor()
}
export const config = {
  baseURL: '',
  header: {
    contentType: 'application/x-www-form-urlencoded'
  },
}
globalInterceptor.response.use((res, config) => {
  let method = config.method;
  let code = res.data.code;
  let msg = res.data.msg;
  if (res.statusCode == 500) {
    uni.showToast({
      icon: 'none',
      title: '服务器发生了点小插曲'
    })
  } else if (res.statusCode == 200) {
    if (method == 'get' && code == 1) {
      uni.hideLoading();
    } else {
      switch (code) {
        case 0:
          break;
        case 401:
          break;
        default:
          uni.showToast({
            icon: 'none',
            title: msg,
            duration: 500
          })
          break;
      }
    }
  }
  return res;
}, (err, config) => {
  uni.hideLoading();
  if (err.errMsg) {
    uni.showToast({
      icon: 'none',
      title: '请检查网络连接'
    })
  }
});
